<template>
	<view v-if="visible">
		<!-- 遮罩层 -->
		<view class="coupon-mask" @click="onClose"></view>

		<!-- 弹窗容器 -->
		<view class="coupon-popup">
			<!-- 关闭按钮 -->
			<view class="close-btn" @click="onClose">
				<text class="close-icon">×</text>
			</view>

			<!-- 门店信息区域 -->
			<view class="store-info">
				<view class="store-header">
					<view class="store-name">{{item.store_label}} {{item.store_detail}}</view>
					
					<view class="navigate-btn" @click="goNavigation">去导航</view>
				</view>
				<view class="store-header">
					<view>电话： {{item.store_mobile}}</view>
				</view>
				<view class="store-detail">
					<view class="detail-item">
						<text class="icon-time">🕒</text>
						<text>时间：08:00-18:00</text>
					</view>
					<!-- <view class="detail-item">
						<text class="icon-location">📍</text>
						<text>地址：{{item.store_label}} {{item.store_detail}}</text>
					</view> -->
					<!-- <view class="detail-item">
						<text class="icon-location">🎁</text>
						<text>下单时间：{{order.product[0].create_time}}</text>
					</view> -->

				</view>
			</view>

			<!-- 二维码区域 -->
			<view class="qr-code-area">
				<view class="qr-code-title">{{order.order_no}}</view>
				<image class="qr-code-img" :src="codeImg">
				</image>
				<view class="qr-code-tip">请向商家出示提货码或确认提货</view>
			</view>

			<!-- 商品信息区域 -->
			<view class="goods-info" v-for='item in order.product'>
				<view class="info-item">
					<view>
						<text class="info-value">{{item.product_name}}</text>
					</view>
					<text class="info-value">× {{item.total_num}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			// 控制弹窗显示/隐藏
			visible: {
				type: Boolean,
				default: false
			},
			item: {
				type: Object,
			},
			order_id: {
				type: Object,
			},
		},
		data() {
			return {
				codeImg: '',
				order: {}
			}
		},

		created() {
			let self = this
			let source = self.getPlatform();
			console.log(this.item)
			self._get(
				'user.order/qrcode', {
					order_id: this.order_id,
					source: source,
					storeid:self.item.user_id
				},
				function(res) {
					uni.hideLoading();
					self.isCodeImg = true;
					self.codeImg = res.data.qrcode;
				}
			);

			self._get('user.order/detail', {
					order_id: self.order_id,
					pay_source: source
				},
				function(res) {
					self.order = res.data.order
					console.log(self.order)
				}
			);

		},
		methods: {
			// 关闭弹窗
			onClose() {
				this.$emit('close');
			},
			// 导航逻辑
			goNavigation() {
				uni.showToast({
					title: '跳转至导航',
					icon: 'none'
				});
				// 实际项目中可调用地图API
				// uni.openLocation({
				//   latitude: 30.5928,
				//   longitude: 114.3055,
				//   name: '门店名称',
				//   address: '门店地址'
				// });
			}
		}
	};
</script>

<style scoped>
	/* 遮罩层样式 */
	.coupon-mask {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.5);
		z-index: 9998;
	}

	/* 弹窗容器样式 */
	.coupon-popup {
		position: fixed;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
		width: 90%;
		max-width: 500px;
		background-color: #fff;
		border-radius: 16px;
		box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
		padding: 40px 16px 24px;
		box-sizing: border-box;
		z-index: 9999;
		max-height: 90vh;
		overflow-y: auto;
	}

	/* 关闭按钮 */
	.close-btn {
		position: absolute;
		top: 12px;
		right: 12px;
		width: 30px;
		height: 30px;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 50%;
		background-color: rgba(0, 0, 0, 0.05);
	}

	.close-icon {
		font-size: 18px;
		color: #666;
	}

	/* 门店信息区域样式 */
	.store-info {
		margin-bottom: 24px;
		padding-top: 10px;
		/* 预留关闭按钮空间 */
	}

	.store-header {
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
		margin-bottom: 12px;
	}

	.store-name {
		font-size: 16px;
		font-weight: 600;
		color: #333;
		line-height: 1.4;
		flex: 1;
		margin-right: 10px;
	}

	.navigate-btn {
		color: #007aff;
		font-size: 14px;
		padding: 4px 10px;
		border: 1px solid #007aff;
		border-radius: 6px;
		white-space: nowrap;
	}

	.store-detail {
		font-size: 14px;
		color: #666;
	}

	.detail-item {
		display: flex;
		align-items: center;
		margin-bottom: 8px;
		line-height: 1.5;
	}

	.icon-time,
	.icon-location {
		margin-right: 6px;
		font-size: 15px;
	}

	/* 二维码区域样式 */
	.qr-code-area {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-bottom: 24px;
		padding: 20px 0;
		border-top: 1px solid #f0f0f0;
		border-bottom: 1px solid #f0f0f0;
		width: 100%;
	}

	.qr-code-title {
		font-size: 14px;
		color: #333;
		margin-bottom: 16px;
		letter-spacing: 0.5px;
	}

	.qr-code-img {
		width: 180px;
		height: 180px;
		margin-bottom: 12px;
		background-color: #f9f9f9;
		padding: 10px;
		border-radius: 8px;
	}

	.qr-code-tip {
		font-size: 13px;
		color: #999;
		text-align: center;
	}

	/* 商品信息区域样式 */
	.goods-info {
		font-size: 14px;
		width: 100%;
	}

	.info-item {
		display: flex;
		justify-content: space-between;
		padding: 8px 0;
		border-bottom: 1px solid #f5f5f5;
	}

	.info-item:last-child {
		border-bottom: none;
	}

	.info-label {
		color: #999;
	}

	.info-value {
		color: #333;
		font-weight: 500;
	}
</style>